﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
	<%
		String sortIds = request.getParameter("sortIds");
		String baseUrl = request.getContextPath();
	%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
		$(document).ready(function(){
			var baseParams = {sortIds:<%=sortIds%>};
			var EXT_QUERY_TIME_OUT = 1200000;
			var sortListStore;
            var sortListGrid;
            
			sortListStore = new Ext.data.JsonStore({
		        url: '${pageContext.request.contextPath}/getSupervisePerson.action',
		        root: 'datas',
				timeout : EXT_QUERY_TIME_OUT,
		        fields: ['id','user_name','telep','superviseTarget','sort','targetName'],
		        baseParams: baseParams,
		        idProperty:'id',//唯一标识(如果不设定唯一标识,则多行记录只会显示一行记录)
		        autoLoad: true
		    });
		    
		    var Menu = new Ext.menu.Menu({ 
            items: [{ 
            text: '上移', 
            iconCls: 'arrow_up', 
            handler: function(){ 
                if(rowIndex == 0) { 
                    return; 
                } 
                var data = sortListGrid.store.data.items[rowIndex].data; 
                var record = new Ext.data.Record({ 
                        id:data.id, 
                        user_name: data.user_name, 
                        telep: data.telep,
                        superviseTarget: data.superviseTarget,
                        sort: data.sort,
                        targetName: data.targetName
                }); 
                var datalow = sortListGrid.store.data.items[rowIndex-1].data; 
                var Ids = new Array();
                Ids.push(data.id);
                Ids.push(datalow.id);
                var sorts = new Array();
                sorts.push(datalow.sort);
                sorts.push(data.sort);
                personParams = {Ids:Ids,sorts:sorts};
                // 发送请求
				Anynote.ajaxRequest({
			    baseUrl: '<%=baseUrl %>',
				baseParams: personParams,
				action: '${pageContext.request.contextPath}/updateSupervisePersonId.action',
				callback: function(jsonResult){
					    sortListGrid.getStore().removeAt(rowIndex);  
		                sortListGrid.getStore().insert(rowIndex - 1, record);  
		                sortListGrid.getSelectionModel().selectRow(rowIndex - 1);  
		                //sortListGrid.getView().refresh();
		                sortListGrid.getStore().reload();
				},
				showWaiting: true,
				failureMsg: '保存失败.'
				});
            }, 
            scope: this 
        }, 
        { 
            text: '下移', 
            iconCls: 'arrow_down',  
            handler: function(){ 
                if(rowIndex < sortListGrid.getStore().getCount() - 1){ 
                    var data = sortListGrid.store.data.items[rowIndex].data; 
                    var record = new Ext.data.Record({ 
                        id:data.id, 
                        user_name: data.user_name, 
                        telep: data.telep,
                        superviseTarget: data.superviseTarget,
                        sort: data.sort,
                        targetName: data.targetName
                    }); 
                    var dataup = sortListGrid.store.data.items[rowIndex+1].data; 
	                var Ids = new Array();
	                Ids.push(data.id);
	                Ids.push(dataup.id);
	                var sorts = new Array();
	                sorts.push(dataup.sort);
	                sorts.push(data.sort);
	                personParams = {Ids:Ids,sorts:sorts,superviseTarget:superviseTarget};
	                // 发送请求
					Anynote.ajaxRequest({
				    baseUrl: '<%=baseUrl %>',
					baseParams: personParams,
					action: '${pageContext.request.contextPath}/updateSupervisePersonId.action',
					callback: function(jsonResult){
						    sortListGrid.getStore().removeAt(rowIndex);
		                    sortListGrid.getStore().insert(rowIndex + 1, record);  
		                    sortListGrid.getSelectionModel().selectRow(rowIndex + 1);
			                //sortListGrid.getView().refresh();
			                sortListGrid.getStore().reload();
					},
					showWaiting: true,
					failureMsg: '保存失败.'
					});
                } 
            }, 
            scope: this 
          }] 
       });
		    
                // 用户数据表格
			    sortListGrid = new Ext.grid.GridPanel({
				id: 'sortListGrid',
				renderTo: 'sortListGridDiv',
				border: false,
				stateful: true,
		        store: sortListStore,
		        loadMask: true,
		        cm: new Ext.grid.ColumnModel({
		            defaults: {
		                width: 100,
		                sortable: true
		            },
			        columns: [
						new Ext.grid.RowNumberer({header:'№',width:50}),
						{id:'id',header: '人员编号', width: 10, hidden: true, sortable: false, dataIndex: 'id'},
						{id:'user_name',header: '派单对象', width: 220, sortable: false, dataIndex: 'user_name'},
			            {id:'telep',header: '手机号', width: 100,sortable: false, dataIndex: 'telep'},
			            {id:'superviseTarget',header: '督办对象编号', width: 60,hidden: true,sortable: false, dataIndex: 'superviseTarget'},
			            {id:'sort',header: '序列号', width: 10, hidden: true,sortable: false, dataIndex: 'sort'},
			            {id:'targetName',header: '督办对象', width: 150,sortable: false, dataIndex: 'targetName'}			
					]
		        }),
		        columnLines: true,
		        listeners: { 
                 rowdblclick: function(sortListGrid, rowIndex, event) { 
            }, 
            contextmenu:function(e){
                var target = e.getTarget();  
                e.stopEvent() ; 
                Menu.showAt(e.getXY()); 
                var view = sortListGrid.getView(); 
                rowIndex = view.findRowIndex(target); 
                sortListGrid.getSelectionModel().selectRow(rowIndex); 
            }
            }
		    });
		    
		    // 设置Grid高度和宽度
		    Anynote.resizeGridTo("sortListGrid", 0, 56);
		    
		});
	</script>
</head>
<body> 
<div id="sortListDiv" style="width:100%;height:100%;">
<div id="sortListGridDiv"></div>
</div>
</body>
</html>